package com.lib.torment.androidlib.widget.networkview;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.lib.torment.androidlib.interfaces.IAdapterConstraint;

/**
 * Created by Torment on 2016/9/12.
 */
public abstract class BaseNetWorkView implements IAdapterConstraint {
    protected Context mContext;
    protected View mParentView;

    private BaseNetWorkView() {
    }

    public BaseNetWorkView(Context context, View view) {
        this.mContext = context;
        this.mParentView = view;
    }

    @Override
    public View getView() {
        return inflaterViewThrow();
    }

    public View inflaterViewThrow() {
        if (mParentView == null) {
            throw new RuntimeException("PartentView is null");
        }
        if (!(mParentView instanceof ViewGroup)) {
            throw new RuntimeException("PartentView is not ViewGroup");
        }

        ViewGroup viewGroup = (ViewGroup) mParentView;
        viewGroup.removeAllViews();

        viewGroup.addView(inflaterView(viewGroup));
        return viewGroup;
    }

    protected abstract View inflaterView(ViewGroup parentView);
}
